﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Maticsoft.Common;

namespace Maticsoft.Web.wap
{
    public partial class UserOrderDetail : BasePage
    {
        int _OrderId = 0;
        protected void Page_Load( object sender, EventArgs e )
        {
            Check();

            int.TryParse(Request.QueryString["id"], out _OrderId);

            InitData();
        }

        protected void InitData()
        {
            try
            {
                BindOrder();
                BindOitem();
                BindDelivery();
            }
            catch (Exception ex)
            {
                Logger.Log4Net.Error(ex.Message + ex.StackTrace);
            }
        }

        protected void BindOrder()
        {
            BLL.Orders ordBLL = new BLL.Orders();
            Model.Orders ordModel = ordBLL.GetModel(_OrderId);
            ltlOrderNo.Text = ordModel.OrderNo;
            ltlOrderStatus.Text = "";
            ltlName.Text = ordModel.Name;
            ltlMobile.Text = ordModel.Mobile;
            BLL.LocationInfo locBLL = new BLL.LocationInfo();
            Model.LocationInfo locModel = locBLL.GetModel((int)ordModel.LocationId);
            if (locModel == null)
            {
                locModel = new Model.LocationInfo();
            }
            ltlAddress.Text = (Convert.ToString(locModel.pName) == "" ? locModel.locationName : locModel.pName + locModel.cName) 
                + ordModel.Address;
            ltlProductTotal.Text = ordModel.ProductPrice.ToString();
            ltlDeliveryFee.Text = ordModel.DeliveryFee.ToString();
            ltlTotal.Text = ordModel.Total.ToString();

            ltlOrderDate.Text = ((DateTime)ordModel.CreateTime).ToString("yyyy-MM-dd HH:mm:ss");

            BLL.OrderStatus staBLL = new BLL.OrderStatus();
            Model.OrderStatus staModel = staBLL.GetModel((int)ordModel.Status);
            ltlOrderStatus.Text = staModel.OrderStatusNameCus;
        }

        protected void BindOitem()
        {
            BLL.Oitems oitBLL = new BLL.Oitems();
            DataSet ds = oitBLL.GetList("IsActive=1 and OrderId=" + _OrderId);
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        protected void BindDelivery()
        {
            BLL.LogisticsInfo logiBLL = new BLL.LogisticsInfo();
            DataSet dss = logiBLL.GetList("OrderId=" + _OrderId + " order by CreateTime");
            Repeater2.DataSource = dss.Tables[0].DefaultView;
            Repeater2.DataBind();
        }
    }
}